<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        border: 3px solid;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <div id="box1">
      box1
      <div id="box2">
        box2
        <div id="box3">
          box3
          <div id="box4">box4</div>
        </div>
      </div>
    </div>
    <script>
      const box1 = document.getElementById("box1");
      const box2 = document.getElementById("box2");
      const box3 = document.getElementById("box3");
      const box4 = document.getElementById("box4");

      box1.onclick = function (e) {
        e.stopPropagation();
        console.log(1);
      };
      box2.onclick = function (e) {
        e.stopPropagation();
        console.log(2);
      };
      box3.onclick = function (e) {
        e.stopPropagation();
        console.log(3);
      };
      box4.addEventListener("click", (e) => {
        e.stopImmediatePropagation();
        console.log(4.1);
      });
      box4.addEventListener("click", (e) => {
        console.log(4.2);
      });
      box4.addEventListener("click", (e) => {
        console.log(4.3);
      });
    </script>
  </body>
</html>
